###############################################################################
#                                                                             #
#    L3q - Light, light, lightweight queue                                    #
#    Copyright (C) 2023  Marcus Pedersén marcus.pedersen@slu.se               #
#                                                                             #
#    This program is free software: you can redistribute it and/or modify     #
#    it under the terms of the GNU General Public License as published by     #
#    the Free Software Foundation, either version 3 of the License, or        #
#    (at your option) any later version.                                      #
#                                                                             #
#    This program is distributed in the hope that it will be useful,          #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
#    GNU General Public License for more details.                             #
#                                                                             #
#    You should have received a copy of the GNU General Public License        #
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
#                                                                             #
###############################################################################




'''
Module contains action classes
and functions for l3q,
required by both daemon, node and client programs.
Action classes are sent as json strings
over https between different l3q programs.
'''



class Action():
    '''
    Base class for actions.
    Subclasses should specify
    needed required slots.
    '''
    __slots__ = ['validate']
    
    def __init__(self) -> None:
        self.validate: str = ""



'''
Client Action classes.
To be sent as json
to l3q darmon.
'''

class CAValidateKey(Action):
    '''
    Client action: Validate Key
    '''
    __slots__: list[str] = ['password', 'hostname']

    def __init__(self) -> None:
        self.password: str = ""
        self.hostname: str = ""

    


class CAGetQueue(Action):
    '''
    Client action: Get Queue
    '''
    __slots__: list[str] = []

    def __init__(self) -> None:
        pass


class CAGetHistory(Action):
    '''
    Client action: Get History
    '''
    __slots__: list[str] = []

    def __init__(self) -> None:
        pass


class CAGetNodeStatus(Action):
    '''
    Client action: Get Node Status
    '''
    __slots__: list[str] = []

    def __init__(self) -> None:
        pass


class CAGetJobInfo(Action):
    '''
    Client action: Get Job Info
    '''
    __slots__ = ['jobid']

    def __init__(self) -> None:
        self.jobid: int = 0



class CAGetTaskInfo(Action):
    '''
    Client action: Get Task Info
    '''
    __slots__ = ['taskid']

    def __init__(self) -> None:
        self.taskid: int = 0



class CAGetTaskList(Action):
    '''
    Client action: Get Task List
    '''
    __slots__ = ['jobid']

    def __init__(self) -> None:
        self.jobid: int = 0





class CASetNodeOnline(Action):
    '''
    Client action: Set Node Online
    '''
    __slots__ = ['node_name']

    def __init__(self) -> None:
        self.node_name: str = ""




class CASetNodeOffline(Action):
    '''
    Client action: Set Node Offline
    '''
    __slots__ = ['node_name']

    def __init__(self) -> None:
        self.node_name: str = ""


class CAAddParallel(Action):
    '''
    Client action: Add Parallel Job
    '''
    __slots__ = ['user', 'name','tasks', 'nodes', 'cores', 'memory', 'depend']

    def __init__(self) -> None:
        self.user: str = ""
        self.name: str = ""
        self.tasks: list[str] = []
        self.nodes: int = 0
        self.cores: int = 0
        self.memory: int = 0
        self.depend: list[int]



class CAAddSequence(Action):
    '''
    Client action: Add Sequence Job
    '''
    __slots__ = ['user', 'name','tasks', 'cores', 'memory', 'depend']

    def __init__(self) -> None:
        self.user: str = ""
        self.name: str = ""
        self.tasks: list[str] = []
        self.cores: int = 1
        self.memory: int = 0
        self.depend: list[int]




class CACancelJob(Action):
    '''
    Client action: Cancel Job
    '''
    __slots__ = ['jobid', 'user']

    def __init__(self) -> None:
        self.jobid: int = 0
        self.user: str = ""



